﻿using Fuse8.ContentManagementFramework.Administration.Attributes;
using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Special;
using Fuse8.ContentManagementFramework.Web.MvcPowered;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Fuse8.ContentManagementFramework.Administration.Models
{
    public sealed class CmsUserContainer : CmsSiteAwareModel
    {
        [GlobalizedRequired("Please enter login", "cms_Users")]
        public string LoginName { get; set; }

        [GlobalizedRequired("Please enter email", "cms_Users")]
        [GlobalizedRegularExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", "Email is not valid", "cms_Users")]
        public string UserEmail { get; set; }

        [GlobalizedRequired("Please enter first name", "cms_Users")]
        public string Firstname { get; set; }

        [GlobalizedRequired("Please enter last name", "cms_Users")]
        public string Lastname { get; set; }

        public string OldPassword { get; set; }

        [StrongPassword]
        public string NewPassword { get; set; }

        [GlobalizedCompare("NewPassword", "Passwords do not match", "cms_Users")]
        public string ReNewPassword { get; set; }

        public bool IsEnabled { get; set; }

        public CmsEntityMetaInformation EntityMetaInformation { get; set; }

        public IList<CmsEntityMetaModel> Metas { get; set; }

        public IList<int> AvailableUserGroups { get; set; }

        public IList<int> SelectedUserGroups { get; set; }

        public IEnumerable<CmsSystemLanguage> AvailableLanguages { get; set; }

        public bool IsAutoGeneratePassword { get; set; }

        public bool IsChangePassword { get; set; }

        public bool IsSendEmail { get; set; }

        public bool IsCanSetPassword { get; set; }

        public string Locale { get; set; }

        public CmsUserContainer()
        {
        }

        public CmsUserContainer(CmsUser cmsUser)
        {
            Id = cmsUser.Id;
            LoginName = cmsUser.LoginName;
            UserEmail = cmsUser.UserEmail;
            Firstname = cmsUser.Firstname;
            Lastname = cmsUser.Lastname;
            IsEnabled = cmsUser.IsEnabled;
            SiteCategory = cmsUser.SiteCategory;
            EntityMetaInformation = cmsUser.EntityMetaInformation;
            Locale = cmsUser.Locale;
        }
    }
}